Chapter 3. HTTP Requests in Laravel
HTTP Requests
What are they?
- An HTTP request is a message sent by a client (such as a web browser) to a server to request a resource or perform an action.
Types of queries
GET
- They are queries that are executed in the URL:
http://alfred.com/hack?hack="123"
In this case, hack is the variable, and its value is 123
Also, this type of queries are used to render parts of the webpage. To get all data and show it to the user
Route::get("", function () {
return "Hello world";
});
POST
- There are three of this type. Actually, they are the same thing, but there are specific differences about functionality and when we must use one
POST
It is the most common, it is used when you send information through a form
<form action="/send" method="POST">
<input type="text" name="name">
<input type="submit" value="Submit">
</form>
Route::post("/send", function () {
return "To create";
});
PUT Y PATCH
They are using to update records
PUT
- To update a whole record
Route::put("/update", function () {
return "To update";
});
PATCH
- To update partially a record
Route::patch("/update-partial", function () {
return "To update";
});
DELETE
- To delete a record
Route::post("/delete", function () {
return "To delete"
});
Info
All of these methods will be more explanied further on.